package cate.game.train.awakenfairy.msg;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.common.util.GameResult;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBTrain;
import cate.game.role.Role;
import cate.game.role.bag.awakenfairy.AwakenFairy;
import cate.game.role.bag.hero.Hero;
import easy.java.dev.note.NoteField;

@ClientMsg(title = "英雄穿觉醒灵器の 请求")
@OperationSetter(GDOperation.AWAKEN_FAIRY_ON)
public class AwakenFairyOnReq implements MsgInput {
    @NoteField(value = "英雄ID", detail = "要给哪一个英雄穿装备")
    public String heroUid;

    @NoteField(value = "位置")
    public byte pos;

    @NoteField(value = "灵器唯一id")
    public String awakenFairyUid;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        Role role = cc.getRole();
        Hero hero = role.getBag().hero.getItem(heroUid);
        if (hero == null) {
            game.notice.message(role, "英雄不存在");
            return;
        }
        AwakenFairy awakenFairy = role.getBag().getAwakenFairy().getItem(awakenFairyUid);
        if(awakenFairy == null){
            game.notice.message(role, "灵器不存在");
            return;
        }
        GameResult<Byte> r = hero.onAwakenFairy(role.toPlayBuildContext(), awakenFairy, pos);
        if (!r.ok()) {
            game.notice.message(role, r.message);
            return;
        }
        cc.sendNow(new AwakenFairyOnResp(heroUid, pos, awakenFairy));
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBTrain.AWAKEN_FAIRY_ON_REQ;
    }
}
